package net.hn.hnms.biz.support.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import net.hn.hnms.biz.support.company.domain.dto.ChartDto;
import net.hn.hnms.biz.support.company.domain.vo.ChartVo;
import net.hn.hnms.biz.support.mapper.RoofabscissionAlarmDayMapper;
import net.hn.hnms.biz.support.mapper.SupportdataAlarmDayMapper;
import net.hn.hnms.biz.support.service.EarlyWarningService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
@DS(value = "smart")
public class EarlyWarningServiceImpl implements EarlyWarningService {

    /**
     * 顶板离层预警Mapper
     */
    @Resource
    private RoofabscissionAlarmDayMapper roofabscissionAlarmDayMapper;

    /**
     * 支架阻力预警Mapper
     */
    @Resource
    private SupportdataAlarmDayMapper supportdataAlarmDayMapper;

    /**
     * 顶板离层报警曲线
     * @param number
     * @return
     */
    @Override
    public ChartVo abscissdataRiskStatistics(String number) {
        ChartVo chartVo = new ChartVo();
        List<String> xlast = new ArrayList<>();
        List<BigDecimal> ylast = new ArrayList<>();
        List<ChartDto> list = null;
        String day = new String("''");
        //1-周，2-月
        if ("1".equals(number)) {
            day = "'6 day'";
//             list =abscissalarmAbnormalMapper.riskStatisticsWeek();
            list = roofabscissionAlarmDayMapper.abscissdataRiskStatistics(day);
        }
        if ("2".equals(number)) {
            day = "'30 day'";
//            list =abscissalarmAbnormalMapper.riskStatisticsMonth();
            list = roofabscissionAlarmDayMapper.abscissdataRiskStatistics(day);
        }

        for (ChartDto chartDto : list) {
            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDto.getTime()));
            ylast.add(chartDto.getValue());
        }
        chartVo.setXData(xlast);
        chartVo.setValeus(ylast);
        return chartVo;
    }

    /**
     * 支架报警曲线
     * @param number
     * @return
     */
    @Override
    public ChartVo supportRiskStatistics(String number) {
        ChartVo chartVo = new ChartVo();
        List<String> xlast = new ArrayList<>();
        List<BigDecimal> ylast = new ArrayList<>();
        List<ChartDto> list = null;
        String day = new String("''");
        //1-周，2-月
        if ("1".equals(number)) {
            day = "'6 day'";
            list = supportdataAlarmDayMapper.supprotRiskStatistics(day);
        }
        if ("2".equals(number)) {
            day = "'30 day'";
            list = supportdataAlarmDayMapper.supprotRiskStatistics(day);
        }

        for (ChartDto chartDto : list) {
            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDto.getTime()));
            ylast.add(chartDto.getValue());
        }
        chartVo.setXData(xlast);
        chartVo.setValeus(ylast);
        return chartVo;
    }

    /**
     * 功能描述: 查询预警数据库的支架预警表(查询支架预警一天内的预警次数)
     * @auther: WangLong
     * @date: 2023/1/3 15:22
     * @param
     * @return int
     */

    @Override
    public int getDaySupportPressureAnomaly() {
        Integer supportPressureAnomaly=supportdataAlarmDayMapper.getDaySupportPressureAnomaly();
        return supportPressureAnomaly.intValue();
    }

    /**
     * 功能描述: 查询预警数据库的顶板预警表(查询顶板预警一天内的预警次数)
     * @auther: WangLong
     * @date: 2023/1/3 15:44
     * @param
     * @return int
     */

    @Override
    public int getRoofSeparationAnomaly() {
        Integer roofSeparationAnomaly = roofabscissionAlarmDayMapper.getRoofSeparationAnomaly();
        return roofSeparationAnomaly.intValue();
    }
}
